package org.mxp.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 队列QC配置信息
 */
@Configuration
public class TtlQueueQCConfig {
    // 交换机Y（死信交换机）
    public static final String EXCHANGE_Y = "Y";
    // 队列QC
    public static final String QUEUE_QC = "QC";

    // 声明队列QC，并绑定到对应的死信交换机Y
    @Bean
    public Queue queueQC() {
        Map<String, Object> args = new HashMap<>(2);
        // 声明当前队列绑定的死信交换机
        args.put("x-dead-letter-exchange", EXCHANGE_Y);
        // 声明当前队列的死信路由key
        args.put("x-dead-letter-routing-key", "YD");
        // 固定写法，生成队列
        return QueueBuilder.durable(QUEUE_QC).withArguments(args).build();
    }

    // 将队列QC绑定到交换机X，routingKey为XC
    @Bean
    public Binding queueQCBindingX(@Qualifier("queueQC") Queue queueQC, @Qualifier("xExchange") DirectExchange xExchange) {
        // 将队列QC绑定到交换机X，并指定路由key为XC
        return BindingBuilder.bind(queueQC).to(xExchange).with("XC");
    }
}
